package com.company.common.auth.handle;

import org.springframework.util.StringUtils;

import com.company.cloud.common.bean.LoginUserInfo;
import com.company.cloud.common.cache.CacheService;
import com.company.cloud.common.constant.BaseReturnEnum;
import com.company.cloud.common.exception.BusinessException;


public class LoginHandle implements AuthHandle{

	private static LoginHandle _handle=new LoginHandle();
	private LoginHandle() {
		
	}
	public static LoginHandle getInstall() {
		return _handle;
	}
	
	@Override
	public LoginUserInfo handle(String token, String url,CacheService cacheService) throws BusinessException {
		if(StringUtils.isEmpty(token)){
	        throw new BusinessException(BaseReturnEnum.NOT_LOGIN);
	    }
		LoginUserInfo loginUserInfo = cacheService.get(token, LoginUserInfo.class);
		if(loginUserInfo == null){
	       	throw new BusinessException(BaseReturnEnum.NOT_LOGIN);
	    }
		if (loginUserInfo.getId() <= 0) {
			throw new BusinessException(BaseReturnEnum.NOT_MOBILE);
		}
		return loginUserInfo;
	}
	
}
